package org.microsites.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.microsites.domain.dao.ProjectDAO;
import org.microsites.domain.model.Entity;
import org.microsites.domain.model.Project;
import org.microsites.service.GroupService;
import org.microsites.service.ProjectService;

public class ProjectServiceImpl extends GenericServiceImpl<Project> implements ProjectService {
	
	private ProjectDAO projectDAO;
	private GroupService groupService;
	
	@Override
	public List<Project> sublistInGroup(Long id) {
		return getDAO().sublistInGroup(id);
	}

	public ProjectDAO getDAO() {
		return projectDAO;
	}

	public void setProjectDAO(ProjectDAO projectDAO) {
		this.projectDAO = projectDAO;
	}

    @Override
    public List<Entity> loadPath(Long id) {
        if (id == null) return new ArrayList<Entity>();

        Project d = this.load(id);
        if (d == null) return new ArrayList<Entity>();
        
        List<Entity> list = (d.getParent() != null) ?
                this.loadPath(d.getParent()) : groupService.loadPath(d.getGroup());
        list.add(d);

        return list;
    }

    public GroupService getGroupService() {
        return groupService;
    }

    public void setGroupService(GroupService groupService) {
        this.groupService = groupService;
    }
}
